package org.bookr.batch.importer;

import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.NonTransientResourceException;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Pawel Tomaszewski
 */
public class ImportReader implements ItemReader<String> {
    private static List<String> elems = new ArrayList<String>();

    static {
        for(int i = 0; i < 30; i++) {
            elems.add("elem#" + i);
        }
    }

    public String read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
        int lastIndex = elems.size()-1;
        String result = null;

        if(lastIndex>=0) {
            result = elems.get(lastIndex);
            elems.remove(lastIndex);
        }

        System.out.println("READER READER READER " + result);
        return result;
    }
}
